package GUI;

import java.awt.LayoutManager;

import javax.swing.JPanel;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.GridLayout;

import logic.Message;
import javax.swing.UIManager;

public class Librarian_Menu extends JPanel {

	private Client_GUI parent;
	
	private JButton btnAddABook;
	private JButton btnUpdateBook;
	private JButton btnDeleteBook;
	
	private boolean stockToggled = false;
	
	public Librarian_Menu(final Client_GUI parent) {
		this.parent = parent;
		this.setBackground(Color.WHITE);
		
		this.setSize(parent.MENU_WIDTH, parent.MENU_HEIGHT);
		
		JButton btnHome = new JButton("Home");
		btnHome.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				Home home = new Home(parent,parent.client.publicMessages);
				parent.RepaintMain(home);
				
			}
		});
		setLayout(new GridLayout(0, 1, 0, 0));
		add(btnHome);
		
		JButton btnSearchMember = new JButton("Search Member");
		btnSearchMember.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				SearchMember topaint = new SearchMember(parent,SearchMember.SEARCH,null);
				parent.RepaintMain(topaint);
				
			}
		});
		add(btnSearchMember);
		
		JButton btnCreateMember = new JButton("Create Member");
		btnCreateMember.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				CreateMember topaint = new CreateMember(parent);
				parent.RepaintMain(topaint);
				
			}
		});
		add(btnCreateMember);
		
		JButton btnSearchBook = new JButton("Search Book");
		btnSearchBook.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				SearchBook topaint = new SearchBook(parent,SearchBook.SEARCH,null);
				parent.RepaintMain(topaint);
				
			}
		});
		add(btnSearchBook);
		
		JButton btnLoanBook = new JButton("Loan Book");
		btnLoanBook.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				Book_opp bookOperations = new Book_opp(parent,Message.CREATE_LOAN_REQUEST,-1);
				parent.RepaintMain(bookOperations);
			}
		});
		add(btnLoanBook);
		
		JButton btnReturnBook = new JButton("Return Book");
		btnReturnBook.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				Return_Book topaint = new Return_Book(parent);
				parent.RepaintMain(topaint);
			}
		});
		add(btnReturnBook);
		
		JButton btnSearchLoans = new JButton("Search Loans");
		btnSearchLoans.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				SearchLoan topaint = new SearchLoan(parent,SearchLoan.SEARCH_LOAN,null);
				parent.RepaintMain(topaint);
			}
		});
		add(btnSearchLoans);
		
		JButton btnSearchOrders = new JButton("Search Orders");
		btnSearchOrders.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				SearchOrder topaint = new SearchOrder(parent);
				parent.RepaintMain(topaint);
			}
		});
		add(btnSearchOrders);
		
		JButton btnOrderABook = new JButton("Order A Book");
		btnOrderABook.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				Book_opp bookOperations = new Book_opp(parent,Message.CREATE_ORDER_REQUEST,-1);
				parent.RepaintMain(bookOperations);
			}
		});
		add(btnOrderABook);
		
		JButton btnManageStock = new JButton("Manage Stock");
		btnManageStock.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				SetStockVisibility(!stockToggled);
			}
		});
		add(btnManageStock);
		
		btnAddABook = new JButton("Add A Book");
		btnAddABook.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				Add_Book topaint = new Add_Book(parent,null);
				parent.RepaintMain(topaint);
			}
		});
		add(btnAddABook);
		
		btnUpdateBook = new JButton("Update Book");
		btnUpdateBook.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				Manage_Stock topaint = new Manage_Stock(parent, SearchBook.SEARCH_FOR_UPDATE);
				parent.RepaintMain(topaint);
			}
		});
		add(btnUpdateBook);
		
		btnDeleteBook = new JButton("Delete Book");
		btnDeleteBook.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Manage_Stock topaint = new Manage_Stock(parent, SearchBook.SEARCH_FOR_DELETE);
				parent.RepaintMain(topaint);
			}
		});
		add(btnDeleteBook);
		
		SetStockVisibility(false);
	}
	
	
	/**
	 * Set the Stock Management button group's visiblity
	 * @param value - visibilty value to set
	 */
	private void SetStockVisibility(boolean value){
		btnAddABook.setVisible(value);
		btnUpdateBook.setVisible(value);
		btnDeleteBook.setVisible(value);
		
		stockToggled = value;
	}


}
